package 天气数据;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Data implements WritableComparable<Data> {
    //年
    private String year;
    //月
    private String month;
    //日
    private String day;
    //小时
    private String hour;
    //温度
    private String temperature;
    //湿度
    private String dew;
    //气压/压强
    private int pressure;
    //风向
    private String wind_direction;
    //风速
    private String wind_speed;
    //天气情况
    private String sky_condition;
    //1小时降雨量
    private String rain_1h;
    //6小时降雨量
    private String rain_6h;


    public int compareTo(Data o) {
        int a = (this.temperature.compareTo(o.temperature));
        int b = (this.wind_speed.compareTo(o.wind_speed));
        if (a == 0) {
            if (b == 0) {
                return o.pressure - this.pressure;
            }
            return b;
        }
        return a;
    }


    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(year);
        dataOutput.writeUTF(month);
        dataOutput.writeUTF(day);
        dataOutput.writeUTF(hour);
        dataOutput.writeUTF(temperature);
        dataOutput.writeUTF(dew);
        dataOutput.writeInt(pressure);
        dataOutput.writeUTF(wind_direction);
        dataOutput.writeUTF(wind_speed);
        dataOutput.writeUTF(sky_condition);
        dataOutput.writeUTF(rain_1h);
        dataOutput.writeUTF(rain_6h);
    }


    public void readFields(DataInput dataInput) throws IOException {
        year = dataInput.readUTF();
        month = dataInput.readUTF();
        day = dataInput.readUTF();
        hour = dataInput.readUTF();
        temperature = dataInput.readUTF();
        dew = dataInput.readUTF();
        pressure = dataInput.readInt();
        wind_direction = dataInput.readUTF();
        wind_speed = dataInput.readUTF();
        sky_condition = dataInput.readUTF();
        rain_1h = dataInput.readUTF();
        rain_6h = dataInput.readUTF();
    }

    @Override
    public String toString() {
        return year + "," + month + "," + day + "," + hour + "," + temperature + "," + dew + "," + pressure + ","
                + wind_direction + "," + wind_speed + "," + sky_condition + "," + rain_1h + "," + rain_6h;
    }

    public void set(String year, String month, String day, String hour, String temperature, String dew, int pressure, String wind_direction, String wind_speed, String sky_condition, String rain_1h, String rain_6h) {
        this.year = year;
        this.month = month;
        this.day = day;
        this.hour = hour;
        this.temperature = temperature;
        this.dew = dew;
        this.pressure = pressure;
        this.wind_direction = wind_direction;
        this.wind_speed = wind_speed;
        this.sky_condition = sky_condition;
        this.rain_1h = rain_1h;
        this.rain_6h = rain_6h;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getHour() {
        return hour;
    }

    public void setHour(String hour) {
        this.hour = hour;
    }

    public String getTemperature() {
        return temperature;
    }

    public void setTemperature(String temperature) {
        this.temperature = temperature;
    }

    public String getDew() {
        return dew;
    }

    public void setDew(String dew) {
        this.dew = dew;
    }

    public int getPressure() {
        return pressure;
    }

    public void setPressure(int pressure) {
        this.pressure = pressure;
    }

    public String getWind_direction() {
        return wind_direction;
    }

    public void setWind_direction(String wind_direction) {
        this.wind_direction = wind_direction;
    }

    public String getWind_speed() {
        return wind_speed;
    }

    public void setWind_speed(String wind_speed) {
        this.wind_speed = wind_speed;
    }

    public String getSky_condition() {
        return sky_condition;
    }

    public void setSky_condition(String sky_condition) {
        this.sky_condition = sky_condition;
    }

    public String getRain_1h() {
        return rain_1h;
    }

    public void setRain_1h(String rain_1h) {
        this.rain_1h = rain_1h;
    }

    public String getRain_6h() {
        return rain_6h;
    }

    public void setRain_6h(String rain_6h) {
        this.rain_6h = rain_6h;
    }
}
